const getAccessToken = require("./getAccessToken.js");
const rp = require("request-promise");

// get post
const callCloudDB = async (ctx, fnNanme, query = {}) => {
  const ACCESS_TOKEN = await getAccessToken();
  const url = `https://api.weixin.qq.com/tcb/${fnNanme}?access_token=${ACCESS_TOKEN}`;
  const options = {
    method: "POST",
    uri: url,
    body: {
      query,
      env: ctx.state.env
    },
    json: true
  };

  return await rp(options)
  .then((res) => {
    return res;
  })
  .catch((err) => {
    
  });

};

module.exports = callCloudDB;